<template>
	<view class="car">
		<!-- 空白页 -->
		
		<view class="container">
			<!-- <view class="c-header">
				<text class="tips">全场加购价</text>
				<text class="desc">再购130元立享满130元可超值换购</text>
				<text class="right">
					去凑单<text class="yticon icon-you"></text>
				</text>
			</view> -->
			<view class="car-list">
				<view class="title_name">
					<view class="tab" v-for="(l,index) in likeList" :key="index" :class="active==index?'active':''" @click="active=index">
						{{l.name}}
					</view>
				
				</view>
				<view class="line"></view>
				<view v-for="(item,index2) in likeList[active].list" class="carbox" :key="index2">
					<view class="list-item" @click="toDetail(item,index2)">
						
						<view class="right">
							<view class="goods-img" >
								<image :src="item.productPicUrl||item.product.fullDefaultImageUrl" mode="aspectFill"></image>
							</view>
							<view class="info">
								<text class="name">{{item.productName}}</text>
								
								<text class="price">￥{{item.FavorablePrice}}</text>
								
							</view>
						</view>
					</view>
				</view>
			</view>
			
		</view>
		<view class="footer-btn">
			<view class="left"></view>
			<view class="right">
				<view class="total">合计：<text class="price">{{likeList[active].total}}</text></view>
				<view class="settlement" @click="toorder">加入购物车</view>
			</view>
			
		</view>


		
	</view>
</template>

<script>
	export default {
		components: {
		},
		data() {
			return {
				empty: false, //空白页现实  true|false
				carList: [],
				total: 0,
				likeList:[],
				id:'',
				iShopId:'',
				fixedId:'',
				active:0
			};
		},
		computed: {
			// if(this.$SysCache.get('token') == null){
			// 	this.hasLogin = false
			// }else{
			// 	this.hasLogin = true
			// }
		},
		onLoad(options) {
			this.id = options.id
			this.iShopId = options.iShopId
			this.fixedId = options.fixedId
			this.onloads();
		},
		onShow() {
			
			
		},
		mounted() {},

		methods: {
			onloads() {
				let data = {
					productId:this.id,
					areaId:null
				}
				this.$Request.post(
					this.$api.httpApi.goods.getFixedSetMenuList + '&token=' + this.$SysCache.get('token') +'&iShopId=' + this.iShopId,{param:data}
				).then(res => {
					if (res.code == 200) {
						
						this.likeList = res.data.fixedsetmenu;
						this.likeList.forEach(item=>{
							this.getData(item)
						})
					}
				});
				
				
				
				
			},
			getData(item){
				let data = {
					id:item.id,
					areaId:null
				}
				this.$Request.post(
					this.$api.httpApi.goods.getProductItems + '&token=' + this.$SysCache.get('token') +'&iShopId=' + this.iShopId,data
				).then(res => {
					if (res.code == 200) {
						this.$set(item,'list',res.data)
						
						// this.likeList = res.data;
						let total = 0
						if(res.data.length>0){
							res.data.forEach(item=>{
								total+=item.FavorablePrice
								
							})
							this.$set(item,'total',total)
						}
						
					}
				});
			},
			toDetail(list, index) {
				console.log("asas", list, index)
				uni.navigateTo({
					url: `/pages/detail/index?id=${list.productId}&iShopId=${list.iShopId}`,
				});
			},
			toorder(){
				let datas = []
				this.likeList[this.active].list.forEach(item=>{
					let temp = {
						"iSKUId": item.product.lsProductSkus[0].id,
						"iProductId": item.productId,
						"onLineOffLine": 0,
						"iQuantity": item.iProductNum,
						"lPackageId": item.combinActivityId,
						"iPackageNum": 1,
						"fixedSale": 1,
						"iShopId":item.iShopId||null
					}
					datas.push(temp)
				})
				let obj = {
					"items": JSON.stringify([datas])
				}
				console.log(obj)
				this.$Request.post(this.$api.httpApi.goods.addCarts + "&token=" + this.$SysCache.get('token'), obj).then(res => {
					if (res.code == 200) {
						uni.showToast({
							title: res.message,
							duration: 2000
						})
						uni.switchTab({
							url:"/pages/car/index"
						})
					}
				})
			}
			
		}
		
	};
</script>

<style lang="scss">
	page {
		background: #f5f5f5;
	}

	.car {
		.empty {
			position: fixed;
			left: 0;
			top: 0;
			width: 100%;
			height: 100vh;
			padding-bottom: 100upx;
			display: flex;
			justify-content: center;
			flex-direction: column;
			align-items: center;
			background: #fff;

			image {
				width: 240upx;
				height: 160upx;
				margin-bottom: 30upx;
			}

			.empty-tips {
				display: flex;
				font-size: $font-sm + 2upx;
				color: $font-color-disabled;

				.navigator {
					color: $uni-color-primary;
					margin-left: 16upx;
				}
			}
		}

		.container {
			// padding-bottom: 184upx;
			padding: 0 20upx 184upx;

			.c-header {
				width: 100%;
				height: 80upx;
				background: rgba(255, 255, 255, 1);
				border: 1upx solid rgba(238, 238, 238, 1);
				border-radius: 9upx 9upx 0upx 0upx;
				display: flex;
				justify-content: space-between;
				align-items: center;
				padding: 0 23upx;
				margin-bottom: 21upx;

				.tips {
					width: 133upx;
					height: 45upx;
					display: inline-flex;
					justify-content: center;
					align-items: center;
					font-size: 20upx;
					font-family: Microsoft YaHei;
					font-weight: bold;
					color: #fff;
					background: rgb(240, 64, 111);
				}

				.desc {
					font-size: 21upx;
					font-family: Microsoft YaHei;
					font-weight: 400;
					color: rgba(102, 102, 102, 1);
					margin-left: 9upx;
				}

				.right {
					flex: 1;
					text-align: right;
					font-size: 26upx;
					font-family: Microsoft YaHei;
					color: rgb(240, 64, 111);

					.icon-you {
						font-size: 26upx;
						color: rgb(240, 64, 111);
					}
				}
			}

			.car-list {
				width: 100%;
				// height:461px;
				background: rgba(255, 255, 255, 1);
				border-radius: 16upx;
				// padding: 0 20upx;
				margin-bottom: 21upx;

				.title_name {
					font-size: 30upx;
					display: flex;
					height: 60upx;
					align-items: center;
					// color: #f0406f;
					padding: 0 20upx;
					justify-content: space-around;
					.left {
						width: 34upx;
						margin-right: 24upx;
						height: 34upx;
						image {
							width: 34upx;
							height: 34upx;
						}
					}
					.tab{
						&.active{
							color: #f0406f;
						}
					}
					
				}
				.line{
					width: 100%;
					height: 1upx;
					background-color: #f00;
					margin: 10upx 0;
				}
				.carbox{
					&:last-child .right{
						border: none;
					}
				}
				.list-item {
					display: flex;
					justify-content: flex-start;
					align-items: center;
					padding: 0 20upx;
					.left {
						width: 34upx;
						margin-right: 24upx;
						height: 34upx;
						image {
							width: 34upx;
							height: 34upx;
						}
					}

					.right {
						flex: 1;
						display: flex;
						justify-content: flex-start;
						align-items: center;
						padding: 32upx 0;
						border-bottom: 2upx solid #ebebeb;

						.goods-img {
							width: 156upx;
							height: 156upx;
							background: rgba(255, 255, 255, 1);
							// border: 1upx solid rgba(217, 217, 217, 1);
							opacity: 0.97;
							border-radius: 2upx;
							margin-right: 31upx;

							image {
								width: 156upx;
								height: 156upx;
							}
						}

						.info {
							flex: 1;
							// height: 156upx;

							.name {
								display: flex;
								font-size: 23upx;
								font-family: Microsoft YaHei;
								font-weight: 400;
								color: rgba(0, 0, 0, 1);
								// line-height: 50upx;
							}

							.osku {
								background: #808080;
								color: #333;
								font-size: 18upx;
								display: inline-flex;
								justify-content: center;
								align-items: center;
								padding: 5upx 10upx;
								border-radius: 5upx;
								width: auto;
							}

							.price {
								display: flex;
								font-size: 33upx;
								font-family: Microsoft YaHei;
								font-weight: 400;
								color: rgba(240, 64, 111, 1);
							}

							.option {
								display: flex;
								font-size: 23upx;
								font-family: Microsoft YaHei;
								font-weight: 400;
								color: rgba(93, 93, 93, 1);
								justify-content: space-between;
								margin-top: 30upx;
							}

							.picker {
								display: flex;
								font-size: 23upx;
								font-family: Microsoft YaHei;
								font-weight: 400;
								color: rgba(93, 93, 93, 1);
								justify-content: flex-start;
								margin-top: 20upx;
								align-items: center;
								.down{
									width: 20upx;
									height: 20upx;
									transform: rotate(90deg);
									margin-left: 10upx;
									margin-top: 5upx;
								}
							}
						}
						
					}

					
				}
			}
		}

		.isiphonx {
			bottom: 80px;
		}

		.footer-btn {
			position: fixed;
			/* left: 30upx; */

			bottom: 0px;
			z-index: 95;
			display: flex;
			justify-content: space-between;
			align-items: center;
			// width: 100%;
			height: 125upx;
			background: #1b1b1b;
			padding: 0 30upx;
			// margin-bottom: 50px;
			left: 0;
			right: 0;

			.left {
				width: 43%;
				height: 100%;
				display: flex;
				align-items: center;
				justify-content: space-between;

				.checkall {
					image {
						width: 34upx;
						height: 34upx;
						margin-right: 22upx;
					}

					font-size: 22upx;
					font-family: Microsoft YaHei;
					font-weight: 400;
					color: rgba(255, 255, 255, 1);
					display: flex;
					align-items: center;
				}

				.freight {
					font-size: 22upx;
					font-family: Microsoft YaHei;
					font-weight: 400;
					color: rgba(136, 136, 136, 1);
				}
			}

			.right {
				width: 57%;
				height: 100%;
				display: flex;
				align-items: center;
				justify-content: space-between;

				.total {
					font-size: 33upx;
					font-family: Microsoft YaHei;
					font-weight: 400;
					color: rgba(255, 255, 255, 1);
					white-space: nowrap;

					.price {
						font-size: 33upx;
						font-family: Microsoft YaHei;
						font-weight: 400;
						color: rgba(240, 64, 111, 1);
					}
				}

				.settlement {
					padding: 14upx 30upx;
					display: flex;
					justify-content: center;
					align-items: center;
					font-size: 31upx;
					font-family: Microsoft YaHei;
					font-weight: 400;
					background: rgba(240, 64, 111, 1);
					border-radius: 29upx;
					color: rgba(255, 255, 255, 1);
					white-space: nowrap;
				}
			}
		}
	}

	/* 规格选择弹窗 */
	.attr-content {
		padding: 10upx 30upx;

		.a-t {
			display: flex;

			image {
				width: 170upx;
				height: 170upx;
				flex-shrink: 0;
				margin-top: -40upx;
				border-radius: 8upx;
			}

			.right {
				display: flex;
				flex-direction: column;
				padding-left: 24upx;
				font-size: $font-sm + 2upx;
				color: $font-color-base;
				line-height: 42upx;

				.price {
					font-size: $font-lg;
					color: $uni-color-primary;
					margin-bottom: 10upx;
				}

				.selected-text {
					margin-right: 10upx;
				}
			}
		}

		.attr-list {
			display: flex;
			flex-direction: column;
			font-size: $font-base + 2upx;
			color: $font-color-base;
			padding-top: 30upx;
			padding-left: 10upx;
		}

		.item-list {
			padding: 20upx 0 0;
			display: flex;
			flex-wrap: wrap;

			text {
				display: flex;
				align-items: center;
				justify-content: center;
				background: #eee;
				margin-right: 20upx;
				margin-bottom: 20upx;
				border-radius: 100upx;
				min-width: 60upx;
				height: 60upx;
				padding: 0 20upx;
				font-size: $font-base;
				color: $font-color-dark;
			}

			.selected {
				background: #fbebee;
				color: $uni-color-primary;
			}
		}
	}

	/*  弹出层 */
	.popup {
		position: fixed;
		left: 0;
		top: 0;
		right: 0;
		bottom: 0;
		z-index: 99;

		&.show {
			display: block;

			.mask {
				animation: showPopup 0.2s linear both;
			}

			.layer {
				animation: showLayer 0.2s linear both;
			}
		}

		&.hide {
			.mask {
				animation: hidePopup 0.2s linear both;
			}

			.layer {
				animation: hideLayer 0.2s linear both;
			}
		}

		&.none {
			display: none;
		}

		.mask {
			position: fixed;
			top: 0;
			width: 100%;
			height: 100%;
			z-index: 1;
			background-color: rgba(0, 0, 0, 0.4);
		}

		.layer {
			position: fixed;
			z-index: 99;
			bottom: 0;
			width: 100%;
			min-height: 40vh;
			border-radius: 10upx 10upx 0 0;
			background-color: #fff;

			.btn {
				height: 66upx;
				line-height: 66upx;
				border-radius: 100upx;
				background: $uni-color-primary;
				font-size: $font-base + 2upx;
				color: #fff;
				margin: 30upx auto 20upx;
			}
		}

		@keyframes showPopup {
			0% {
				opacity: 0;
			}

			100% {
				opacity: 1;
			}
		}

		@keyframes hidePopup {
			0% {
				opacity: 1;
			}

			100% {
				opacity: 0;
			}
		}

		@keyframes showLayer {
			0% {
				transform: translateY(120%);
			}

			100% {
				transform: translateY(0%);
			}
		}

		@keyframes hideLayer {
			0% {
				transform: translateY(0);
			}

			100% {
				transform: translateY(120%);
			}
		}
	}
</style>
